﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Media.Imaging;
using System.Windows.Markup;
using System.Windows;

using TableTop.DataManagement;
using TableTop.Presentation.Controls;

namespace TableTop
{
    public static class AddonHelper
    {
        public static Guid GUID
        {
            get
            {
                GuidAttribute gaAttribute = null;
                Assembly aCurrentAssembly = null;
                Guid gdCurrentGuid = Guid.Empty;

                aCurrentAssembly = Assembly.GetExecutingAssembly();
                gaAttribute = (GuidAttribute)aCurrentAssembly.GetCustomAttributes(typeof(GuidAttribute), false)[0];
                gdCurrentGuid = new Guid(gaAttribute.Value);
                return gdCurrentGuid;
            }
        }

        public static string Name
        {
            get
            {
                AssemblyTitleAttribute ataAttribute = null;
                Assembly aCurrentAssembly = null;
                String strCurrentTitle = String.Empty;

                aCurrentAssembly = Assembly.GetExecutingAssembly();
                ataAttribute = (AssemblyTitleAttribute)aCurrentAssembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0];
                strCurrentTitle = ataAttribute.Title;
                return strCurrentTitle;
            }
        }

        public static ResourceDictionary Resources
        {
            get
            {
                return new Presentation.Themes.Generic();
            }
        }

        public static string Description
        {
            get
            {
                AssemblyDescriptionAttribute ataAttribute = null;
                Assembly aCurrentAssembly = null;
                String strCurrentTitle = String.Empty;

                aCurrentAssembly = Assembly.GetExecutingAssembly();
                ataAttribute = (AssemblyDescriptionAttribute)aCurrentAssembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false)[0];
                strCurrentTitle = ataAttribute.Description;
                return strCurrentTitle;
            }
        }        

        public static Type GetAddonType(TableTopControls RequestedType)
        {
            //Assembly aCurrentAssembly = null;
            Type tRequestedType = null;

            //aCurrentAssembly = Assembly.GetCallingAssembly();

            switch (RequestedType)
            {
                case TableTopControls.Unknown:
                    throw new ArgumentException("Cannot get Unknown type");

                case TableTopControls.CharacterSheetEditor:
                    tRequestedType = typeof(GenericRPGEntryPoint);
                    break;
                default:
                    throw new ArgumentException("Argument out of range");
            }

            return tRequestedType;
        }

        public static object CreateAddonTypeInstance(TableTopControls RequestedType)
        {
            Object objResult = null;

            switch (RequestedType)
            {
                case TableTopControls.Unknown:
                    throw new ArgumentException("Cannot instantiate an Unknown type");

                case TableTopControls.CharacterSheetEditor:
                    objResult = new GRPGCharacterSheetEditor();
                    break;

                default:
                    throw new ArgumentException("Argument out of range");
            }

            return objResult;
        }

        public static String AddonIcon
        {
            get
            {
                Assembly aCurrentAssembly = null;
                String strPackString = String.Empty;
                String strAssemblyName = String.Empty;

                aCurrentAssembly = Assembly.GetExecutingAssembly();
                strAssemblyName = aCurrentAssembly.GetName().Name;
                strPackString = String.Format("pack://application:,,,/{0};component/Images/rpg_dock_icon.png",
                                              strAssemblyName);
                return strPackString;
            }
        }
    }
}
